/* 
 * File:   wrapper.h
 * Author: grm
 *
 * Created on 1 mars 2011, 20:48
 */

#ifndef WRAPPER_H
#define	WRAPPER_H




static const char * ENCTOOLS_VERSION = "0.0.1";
static const char * ENCTOOLS_NAME = "enctools";
static const char * ENCTOOLS_COMPANY = "enctools-inc";

#define MAX_FILENAME_LENGTH 200
#define MAX_REELS    30 /* Soft limit */

#define ENCTOOLS_ERROR -1
#define ENCTOOLS_SUCCESS 0
#define ENCTOOLS_WARN 1

typedef struct filelist {
    char** files;
    int count;
} filelist_t;





/* ASDCP essences*/
#define AET_UNKNOWN 0
#define AET_MPEG2_VES 1
#define AET_JPEG_2000 2
#define AET_PCM_24b_48k 3
#define AET_PCM_24b_96k 4
#define AET_TIMED_TEXT 5
#define AET_JPEG_2000_S 6

enum XML_NAMESPACE {
    XML_NS_UNKNOWN,
    XML_NS_INTEROP,
    XML_NS_SMPTE
};

/* XML Namespaces */
static const char *XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";

static const char *NS_CPL[] = {"None",
    "http://www.digicine.com/PROTO-ASDCP-CPL-20040511#",
    "http://www.smpte-ra.org/schemas/429-7/2006/CPL"};

static const char *NS_PKL[] = {"None",
    "http://www.digicine.com/PROTO-ASDCP-PKL-20040311#",
    "http://www.smpte-ra.org/schemas/429-8/2007/PKL"};

static const char *NS_AM[] = {"None",
    "http://www.digicine.com/PROTO-ASDCP-AM-20040311#",
    "http://www.smpte-ra.org/schemas/429-9/2007/AM"};

static const char *NS_CPL_3D[] = {"None",
    "http://www.digicine.com/schemas/437-Y/2007/Main-Stereo-Picture-CPL",
    "http://www.smpte-ra.org/schemas/429-10/2008/Main-Stereo-Picture-CPL"};

/* Digital signature canonicalization method algorithm */
static const char *DS_DSIG = "http://www.w3.org/2000/09/xmldsig#";

/* Digital signature canonicalization method algorithm */
static const char *DS_CMA = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";

/* Digital signature digest method algorithm */
static const char *DS_DMA = "http://www.w3.org/2000/09/xmldsig#sha1";

/* Digital signature signature method algorithm */
static const char *DS_SMA[] = {"None",
    "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
    "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"};

/* Digital signature transport method algorithm */
static const char *DS_TMA = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";

typedef struct {
    char uuid[40];
    int essence_type;
    int duration;
    int entry_point;
    int xml_ns;
    int stereoscopic;
    char size[18];
    char annotation[80];
    char edit_rate[20];
    char frame_rate[20];
    char sample_rate[20];
    char aspect_ratio[20];
    char digest[40];
    char filename[MAX_FILENAME_LENGTH];
} asset_t;


typedef unsigned char byte_t;

typedef struct {
    char uuid[40];
    char size[18];
    char digest[40];
    char filename[128];
} cpl_t;

typedef struct {
    char uuid[40];
    char size[18];
    char filename[128];
} pkl_t;

typedef struct {
    asset_t MainPicture;
    asset_t MainSound;
    asset_t MainSubtitle;
} reel_t;

typedef struct {
    asset_t asset_list[3];
    int asset_count;
} asset_list_t;

typedef struct {
    int cinema_profile;
    int encoder;
    int frame_rate;
    int stereoscopic;
    int slide;
    int log_level;
    int entry_point;
    int duration;
    int digest_flag;
    int ns;
    int encrypt_header_flag;
    int key_flag;
    int delete_intermediate;
    byte_t key_id[16];
    byte_t key_value[16];
    int write_hmac;
    int xyz;
    int quality;
    int threads;
    int xml_sign;
    int xml_sign_certs;
    char *root_cert_file;
    char *ca_cert_file;
    char *signer_cert_file;
    char *private_key_file;
    char basename[40];
    char timestamp[30];
    char issuer[80];
    char creator[80];
    char annotation[80];
    char title[80];
    char kind[15];
    char rating[5];
    int reel_count;
    cpl_t cpl;
    pkl_t pkl;
    reel_t reel[MAX_REELS];
} context_t;

enum LOG_LEVEL {
    LOG_NONE = 0,
    LOG_ERROR,
    LOG_WARN,
    LOG_INFO,
    LOG_DEBUG
};

extern "C" int write_mxf(context_t *context, filelist_t *filelist, char *output_file);
extern "C" int get_file_essence_type(char *filename);

//Internal functions
#include <KM_error.h>
Kumu::Result_t write_j2k_mxf(context_t *context, filelist_t *filelist, char *output_file);
Kumu::Result_t write_j2k_s_mxf(context_t *context, filelist_t *filelist, char *output_file);
Kumu::Result_t write_pcm_mxf(context_t *context, filelist_t *filelist, char *output_file);
Kumu::Result_t write_mpeg2_mxf(context_t *context, filelist_t *filelist, char *output_file);

#endif	/* WRAPPER_H */

